//
//  JsonChange.m
//  test
//
//  Created by Sam on 16/10/6.
//  Copyright © 2016年 AP-EC. All rights reserved.
//

#import "JsonChange.h"

@implementation JsonChange
+(NSString *)DicToJson:(NSDictionary *)dict{
   
    NSError *error = nil;
    
    //    NSData *data = [NSJSONSerialization dataWithJSONObject:dic options:kNilOptions error:nil];
    NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    
    if (error) {
        NSLog(@"%@", @"json格式化错误");
        return nil;
    }
//    NSLog(@"%@", data);
    
    NSString *jsonString = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    
    return jsonString;
//    NSLog(@"%@", jsonString);
    
    //将json data 转成原本的基本数据类型
//    id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
//    NSLog(@"%@", obj);
    
}

@end
